﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 暑假作业
{
    public partial class goodsInfo_add : Form
    {
        
        public goodsInfo_add()
        {
            InitializeComponent();
        }
        public goodsInfo goodsInfo;
        //提交
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text!=""&&textBox2.Text!=""&&textBox3.Text!=""&&textBox4.Text!="")
            {
                var sql = $"insert into goods values('{textBox1.Text}','{textBox2.Text}','{textBox3.Text}','{textBox4.Text}','{comboBox1.Text}')";
                int a = DBHelper.insert(sql);
                if (a==1)
                {
                    MessageBox.Show("新增成功");
                    var sql1 = "select  goodsid,GName,UnitPrice,Manufactrue,category from goods";
                    DataSet ds = DBHelper.show(sql1);
                    goodsInfo.dataGridView1.DataSource = ds.Tables[0];
                }
                else
                {
                    MessageBox.Show("新增失败");
                }
            }
            else
            {
                MessageBox.Show("请输入信息");
            }
        }
        //关闭
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void goodsInfo_add_Load(object sender, EventArgs e)
        {
            //焦点和加载时
            textBox1.Focus();
            comboBox1.SelectedIndex = 0;
        }
    }
}
